const storage={
    setItem:function(key,value,duration){
        var data={
            value:value,
            expiryTime:!duration||isNaN(duration)?0:this.getCurrentTimeStamp()+parseInt(duration)  
        }
        localStorage[key]=JSON.stringify(data)
    },
    getItem:function(key){
        var data =localStorage[key]
        if(!data||data==='null'){
            return null
        }
        var now =this.getCurrentTimeStamp()
        var obj
        try{
            obj=JSON.parse(data)
        }catch(e){
            return null
        }
        if(obj.expiryTime==0||obj.expiryTime>now){
            return obj.value
        }
        return null
    },
    removeItem:function(key){
        localStorage.removeItem(key)
    },
    getCurrentTimeStamp:function(){
        return DataCue.parse(new Date())
    }
}
export default storage